package com.framework.controller.yhbcontroller;

import com.framework.exception.util.RespResult;
import com.framework.service.yhbservice.YhbUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 用户模块
 *
 * @author ck
 * @date 2018/8/30 10:51
 */
@RestController
@Api(value="用户模块",tags={"用户模块"})
@RequestMapping(value = "yhb")
public class YhbUserController {
	/**
	 * 代理商基础信息
	 */
	@Autowired
	private YhbUserService yhbUserService;


	/**
	 * 功能描述: 根据token获取当前人登录信息
	 * @param token 登录所需的token
	 */
	@GetMapping("user/getUserByToken")
	@ApiOperation("根据token获取用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录所产生的token",dataType ="string",paramType = "query",required = true)
	})
	public RespResult getUserByToken(String token) {
		Map<String,Object> map = yhbUserService.getUserByToken(token);
		return RespResult.ok(map);
	}

	/**
	 * 注册,添加商户信息，以及绑定终端
	 * @param phone
	 * @param deptId
	 * @param sn
	 * @return
	 */
	@PostMapping("register")
	@ApiOperation("注册")
	@ApiImplicitParams({
			@ApiImplicitParam(name="phone",value="手机号码",dataType ="string",paramType = "query",required = true),
			@ApiImplicitParam(name="deptId",value="渠道id",dataType ="Long",paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="终端sn",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="username",value="姓名",dataType ="String",paramType = "query",required = true)

	})
	public RespResult register(String phone,Long deptId,String sn,String username){
		Map<String,Object>map=yhbUserService.registUser(phone,deptId,sn,username);
		return RespResult.ok(map);
	}

	/**
	 * 修改头像
	 * @param token
	 * @param headImg
	 * @return
	 */
	@GetMapping("/user/updateHeadImg")
	@ApiOperation("修改头像")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="headImg",value="头像路径",dataType ="String",paramType = "query",required = true)
	})
	public RespResult updateHeadImg(String token,String headImg){
		yhbUserService.updateHeadImg(token,headImg);
		return RespResult.ok();
	}

	/**
	 * 设置交易密码
	 * @param token
	 * @param password
	 * @return
	 */
	@GetMapping("/user/setTradePassword")
	@ApiOperation("设置交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="password",value="密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="confPassword",value="确认密码",dataType ="String",paramType = "query",required = true)
	})
	public RespResult setTradePassword(String token,String password,String confPassword){
		yhbUserService.setTradePassword(token,password,confPassword);
		return RespResult.ok();
	}

	/**
	 * 更新交易密码
	 * @param token
	 * @param password
	 * @return
	 */
	@PostMapping("/user/updateTradePassword")
	@ApiOperation("修改交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="password",value="密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="confPassword",value="确认密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="oldPassword",value="老密码",dataType ="String",paramType = "query",required = true)
	})
	public RespResult updateTradePassword(String token,String password,String confPassword,String smsCode,String oldPassword){
		yhbUserService.updateTradePassword(token,password,confPassword,smsCode,oldPassword);
		return RespResult.ok();
	}

	/**
	 * 提现
	 * @param token
	 * @param takeAmount
	 * @return
	 */
	@PostMapping("/user/takeMoney")
	@ApiOperation("提现")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="takeAmount",value="提现金额",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="password",value="提现密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="yhbBankId",value="银行卡id",dataType ="String",paramType = "query",required = true)
	})
	public RespResult takeMoney(String token,String takeAmount,String password,String yhbBankId){
		yhbUserService.takeMoney(token,takeAmount,password,yhbBankId);
		return RespResult.ok();
	}

	@PostMapping("/user/toTakePage")
	@ApiOperation("进入提现页面")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
	})
	public RespResult toTakePage(String token){
		Map<String, Object> map = yhbUserService.toTakePage(token);
		return RespResult.ok(map);
	}

	/**
	 * 更新交易密码
	 * @param token
	 * @param password
	 * @return
	 */
	@PostMapping("/user/forgetTradePassword")
	@ApiOperation("忘记交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="password",value="密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="confPassword",value="确认密码",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="smsCode",value="验证码",dataType ="String",paramType = "query",required = true),
	})
	public RespResult forgetTradePassword(String token,String password,String confPassword,String smsCode){
		yhbUserService.forgetTradePassword(token,password,confPassword,smsCode);
		return RespResult.ok();
	}
	@PostMapping("/user/updateIdentity")
	@ApiOperation("修改身份证号")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="identity",value="身份证号",dataType ="String",paramType = "query",required = true),
			@ApiImplicitParam(name="smsCode",value="验证码",dataType ="String",paramType = "query",required = true)
	})
	public RespResult updateIdentity(String token,String identity,String smsCode){
		yhbUserService.updateIdentityByToken(token,identity,smsCode);
		return RespResult.ok();
	}

	@PostMapping("/user/queryOwnerBySn")
	@ApiOperation("客服列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType ="String",paramType = "query",required = true)
	})
	public RespResult queryOwnerBySn(String token){
		List<Map<String,Object>> list=yhbUserService.queryOwnerBySn(token);
		return RespResult.ok().put("list",list);
	}

}
